<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //1.查找
        //2.顺序查找
        arr01=[31,12,45,33,24,16,54,27,19,25,7,65];
        //数组的遍历
        //1.for(i=0)
        for (i=0;i<arr01.length;i++){
            document.write(arr01[i]+" ");
        }   
        document.write("<br>")
        //2.for in对索引号进行遍历
        for (index in arr01){
            document.write(arr01[index]+" ");
        }
        document.write("<br>");
        //3.for of 对值进行遍历
        for (e of arr01){
            document.write(e + " ");
        }
        //flag = false;
        for(i=0;i<arr01.length;i++){
            if(44===arr01[i]){
                //flag=true;
                break;
            }
        }
        if(i<arr01.length){
            console.log("44在数组中");
        }else{
            console.log("44不在数组中");
        }
        //2.二分查找
        arr02=[7,12,16,19,24,25,27,31,33,45,54,65];
        flag=false;
        pivot=33;
        for(i=0,j=arr02.length-1;i<=j && i<arr02.length-1 && j>=0; i++,j--){
            mid=Math.floor((i+j)/2);
            if(arr02[mid]<pivot){
                i=mid+1;
            }else if(arr02[mid]>pivot){
                j=mid-1;
            }else if(arr02==pivot){
                flag=true;
                break;
            }
        }
        if(flag){
            console.log(pivot,"在数组中");
        }else{
            console.log(pivot,"不在数组中");
        }    
    </script>
</body>
</html>